package Partition;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-02-24
 * Time:18:40
 * Text：493-翻转对
 */
public class Text8 {
    static int[] array;
    public static int qsort(int[] nums,int l,int r){
        array=new int[nums.length];
        if(l>=r)return 0;
        int mid=(l+r)/2;
        int num=0;
        num+=qsort(nums,l,mid);
        num+=qsort(nums,mid+1,r);

        int cur1=l,cur2=mid+1,i=0;
        while(cur2<=r) {
            while(cur1<=mid && nums[cur1] / 2.0 <= nums[cur2] ){
                cur1++;
            }
            if(cur1>mid)break;
            num += mid + 1 - cur1;
            cur2++;
        }
        cur1=l;cur2=mid+1;i=0;
        while(cur1<=mid && cur2<=r){
            if(nums[cur1]>nums[cur2]){
                array[i++]=nums[cur2++];
            }else{
                array[i++]=nums[cur1++];
            }
        }
        while(cur1<=mid) array[i++]=nums[cur1++];
        while(cur2<=r) {
            array[i++]=nums[cur2++];
        }
        for(int j=l;j<=r;j++){
            nums[j]=array[j-l];
        }
        return num;
    }
    public static int reversePairs(int[] nums) {
        return qsort(nums,0,nums.length-1);
    }
    public static void main(String[] args) {
        int a=2147483647*2;
        System.out.println(a);
        int[] array={2,4,3,5,1};
        reversePairs(array);
    }
}
